/**
 * @Title: DictionaryController
 * @Package cn.com.yiqi.wsc.portal.controller.admin
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2017/3/6 10:52
 * @version V1.0
 */
package cn.com.yiqi.wsc.portal.controller.admin;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.dictionary.entity.DictionaryEntity;
import cn.com.yiqi.wsc.portal.controller.admin.ro.DictionaryRO;
import cn.com.yiqi.wsc.service.dictionary.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: DictionaryController
 * @Description: TODO
 * @date 2017/3/6 10:52
 */
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    @RequestMapping(value = "/list/{code}", method = RequestMethod.GET)
    public Result getListByCode(@PathVariable String code) {
        Result result = new Result();
        List<DictionaryEntity> list = dictionaryService.getListByCode(code);
        result.setReturnValue(list);
        return result;
    }


    @RequestMapping(value = "/list/parentCode", method = RequestMethod.GET)
    public Result getListByParentCode(@RequestBody DictionaryRO dictionaryRO) {

        Result result = new Result();

        String parentCode = dictionaryRO.getParentCode();

        if (parentCode == null || parentCode.isEmpty()) {
            result.setStatus(ResultStatusEnum.参数错误.getCode());
            result.setErrMsg("参数错误");
            return result;
        }

        result = dictionaryService.getListByParentCode(parentCode, dictionaryRO.getName());

        return result;
    }

}
